<?php
 
/*//禁用错误报告
error_reporting(0);

//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);

//报告所有错误
error_reporting(E_ALL);*/
 
class clerror{
    public static $cltab;
	public function __construct(){
	    self::$cltab=new Cltable();	
		$this->setErrorHandler();
	}
	public function __destruct(){}	
	public function setErrorHandler(){
	    set_error_handler ('clerror::errorHandler');
    }
	
	//实际上是系统遇到错误时的回调函数。语法结构有  window.addEventListener('resize',Callback,flase)相似
	//clerror::errorHandler 相当于callback
	public static function errorHandler (
	$error_level, $error_message, $file, $line,$error_context) {
 		 if (!(error_reporting() & $error_level)) {
        // This error code is not included in error_reporting
        return;
        } 
		//global $tab;
    switch ($error_level) {
		//提醒级别
        case E_NOTICE:
		 $error_type = '<span style="color:#099;">E_NOTICE</span>';
            break;
        case E_USER_NOTICE:
            $error_type = '<span style="color:#093;">E_USER_NOTICE</span>';
            break;
		
		//警告级别
        case E_WARNING:
		$error_type = '<span style="color:#660;">E_WARNING</span>';
            break;
        case E_USER_WARNING:
            $error_type = '<span style="color:#660;">E_USER_WARNING</span>';
            break;
		
		//错误级别
        case E_ERROR:
		    $error_type = '<span style="color:red;">E_ERROR</span>';
            break;
        case E_USER_ERROR:
            $error_type = '<span style="color:#f60;">E_USER_ERROR</span>';
            $EXIT = TRUE;
            break;
		
		//其他未知错误
        default:
            $error_type = '['.$error_level.']';
            $EXIT = TRUE;
            break;
    }
 
	if(array_key_exists("php_errormsg", $error_context)){
		$php_errormsg=$error_context['php_errormsg'];
	}else{
	    $php_errormsg='';	
	}
	
	$desc='<b><span style="color:#f80;">'.$error_type.':</span></b> <span style="color:#3a3;">'.$error_message
	.'</span><span style="color:#80f;"> in </span><span style="color:#f08;"><b>'
	.$file.'</b></span><span style="color:#80f;"> on line </span><b><span style="color:#880;">'
	.$line.'</b>';
	
	self::$cltab->export (array(
	'level'=>$error_level,
	'type'=>$error_type,
	'message'=>$error_message,
	'file'=>$file, 
	'line'=>$line,
	'error_context'=> $php_errormsg
	,'-description-'=>$desc 
	 ));
     //return true 隐藏系统的报错;
        return true;
     }
}
?>